package org.UserHouse.Dao.Imp;

import org.UserHouse.Dao.FavoriteDao;
import org.UserHouse.Utils.Dbutils;
import org.UserHouse.entity.Favorite;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author bin
 * @date 2024-12-16
 */

public class FavoriteDaoImp implements FavoriteDao {
    @Override
    public List<Favorite> SelectFavorite() {
        List<Favorite> list = new ArrayList<>();
        String sql = "select f_id,u_id,h_id,f_date from h_favorite";
        Connection conn = Dbutils.getConnection();
        PreparedStatement pst = null;
        ResultSet rst = null;
        try {
            pst = conn.prepareStatement(sql);
            rst = pst.executeQuery();
            while (rst.next()) {
                Favorite favorite = new Favorite();
                int Fid = rst.getInt(1);
                int Uid = rst.getInt(2);
                int Hid = rst.getInt(3);
                Date Fdate = rst.getDate(4);

                favorite.setFid(Fid);
                favorite.setUid(Uid);
                favorite.setHid(Hid);
                favorite.setFdate(Fdate);

                list.add(favorite);


            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    @Override
    public int AddFavorite(Favorite favorite) {
        return 0;
    }

    @Override
    public int UpdateFavorite(Favorite favorite) {
        return 0;
    }

    @Override
    public int DeleteFavorite(int Fid) {
        return 0;
    }
}
